package com.primaryAlgorithm;

import java.lang.reflect.Array;

/**
 * Description:
 * Copyright:   Copyright (c)2019
 * Company:     zefu
 *
 * @author: 张李鑫
 * @version: 1.0
 * Create at:   2021-09-27 16:10:22
 * <p>
 * Modification History:
 * Date         Author      Version     Description
 * ------------------------------------------------------------------
 * 2021-09-27     张李鑫                     1.0         1.0 Version
 */
public class MoveZeroes {

    public static void moveZeroes(int[] nums) {
        if (null == nums || nums.length < 2) {
            return;
        }
        int end = nums.length - 1;
        int i = 0;
        while (i < end) {
            if (nums[i] == 0) {
                swap(nums, end, i);
                end--;
            } else {
                i++;
            }
        }
    }

    public static void swap(int[] arr, int j, int i) {
        int temp = arr[i];
        arr[i] = arr[j];
        arr[j] = temp;
    }


    public static void main(String[] args) {
        int[] arr = new int[]{1, 0, 8, 0, 89, 0, 870, 0};

        moveZeroes(arr);
        System.out.println(123);
    }
}
